<template>
  <div>
<!--    当前用户名信息：{{ user.id }}-->
<br><br><br>
    <el-form :model="query" status-icon :rules="rules" ref="ruleForm"  class="demo-ruleForm" label-width="550px">
      <el-form-item label="旧密码" prop="oldPassword">
        <el-input  v-model="query.oldPassword" autocomplete="off" style="width: 280px;" show-password></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="newPassword">
        <el-input  v-model="query.newPassword" autocomplete="off" style="width: 280px;" show-password></el-input>
      </el-form-item>
      <el-form-item label="确认新密码" prop="newPassword2">
        <el-input  v-model="query.newPassword2" autocomplete="off" style="width: 280px;" show-password></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="forInfo()">重置</el-button>
        <el-button type="primary" @click="Info()">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>

export default {
  data() {
    return {
      user: {},
      query: {
        oldPassword: "",
        newPassword: "",
        newPassword2: "",
      },
      rules: {
        oldPassword: [
          {required: true, message: '请输入旧密码', trigger: 'blur'},
        ],
        newPassword2: [
          {required: true, message: '请输入新密码', trigger: 'blur'},
        ],
        newPassword: [
          {required: true, message: '请再次输入新密码', trigger: 'blur'},
        ],
      }
    };

  },
  methods: {
    Info() {
      if (this.query.newPassword != this.query.newPassword2) {
        this.$message.error("两次输入密码不一致,请重新输入!!")
      }else {
        const config = {
          headers: {"token": localStorage.getItem("token")}
        }
        this.axios.post("/user/Info?userId=" + this.user.id, this.query, config).then((res) => {
          if (res.data.code == 200) {
            this.$message.success(res.data.message);
            this.forInfo();
          }else {
            this.$message.error(res.data.message);

          }
        })
      }
    },
    forInfo() {
      this.query = {
        oldPassword: "",
        newPassword2: "",
        newPassword: "",
      }
    }
  },
  created() {
    this.user = JSON.parse(localStorage.getItem("user"));
  }
}


</script>
<style>

</style>
